unit Unit4; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, sqldb, db, FileUtil, LResources, Forms, Controls, Graphics,
  Dialogs, ExtCtrls, Buttons, StdCtrls, DBGrids;

type

  { TForm4 }

  TForm4 = class(TForm)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    ds: TDatasource;
    DBGrid: TDBGrid;
    Edit1: TEdit;
    Label1: TLabel;
    Panel1: TPanel;
    Panel2: TPanel;
    query: TSQLQuery;
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
    idx_art, idx_jm : integer;

  end;

var
  Form4: TForm4; 

implementation

{ TForm4 }

procedure TForm4.FormShow(Sender: TObject);
begin
  if form4.query.Active then form4.query.Close;

  form4.query.SQL.Clear;
  form4.query.SQL.Add('select art.idx "ArtIdx",art.nazwa_art "Artykul", jm.nazwa_jm "JM", jm.idx "JmIdx"');
  form4.query.SQL.Add('from artykuly art, jednm jm');
  form4.query.SQL.Add('where art.idx_jm = jm.idx order by nazwa_art');
  form4.query.Open;

  form4.query.First;
  while not form4.query.EOF and (form4.query.FieldByName('ArtIdx').AsInteger <> idx_art) do form4.query.Next;

end;

procedure TForm4.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  form4.query.Close;

end;


initialization
  {$I unit4.lrs}

end.

